home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / bin / delcr.c < prev   
C/C++ Source or Header  |  1995-08-08  |  866b  |  54 lines

  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. #ifndef    MSDOS
  7. #define RMODE    "r"
  8. #define WMODE    "w"
  9. #else
  10. #define RMODE    "rb"
  11. #define WMODE    "wb"
  12. #endif
  13.  
  14. static    void    copy(FILE *ffp, FILE *tfp);
  15.  
  16. main(int argc, char *argv[])
  17. {
  18.     FILE    *ffp, *tfp;
  19.     char    *ffile, tfile[20];
  20.  
  21.     strcpy(tfile, "tfXXXXXX");
  22.     mktemp(tfile);
  23.     while (--argc)  {
  24.         if (NULL == (ffp = fopen(ffile=*++argv, RMODE)))  {
  25.             fprintf(stderr, "Can't open %s\n", ffile);
  26.             continue;
  27.         }
  28.         if (NULL == (tfp = fopen(tfile, WMODE)))  {
  29.             fprintf(stderr, "Can't create %s\n", tfile);
  30.             fclose(ffp);
  31.             continue;
  32.         }
  33.         copy(ffp, tfp);
  34.         fclose(ffp);
  35.         fclose(tfp);
  36.         unlink(ffile);
  37.         rename(tfile, ffile);
  38.     }
  39. }
  40.  
  41. static    void    copy(FILE *ffp, FILE *tfp)
  42. {
  43.     register int    c;
  44.  
  45.     while (1)  {
  46.         c = getc(ffp);
  47.         if (c == EOF  &&  feof(ffp))
  48.             return;
  49.         if (c != '\r'  &&  c != 26)
  50.             putc(c, tfp);
  51.     }
  52. }
  53.  
  54.